﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;
using Kooboo.Domain;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IEntityUpdateCommand<ISupportTicket>))]
    public class SupportTicketUpdateCommand:EntityUpdateCommand<ISupportTicket>
    {
        protected override string TableName
        {
            get { return "SupportTicket"; }
        }

        protected override KeyValuePair<string, object> BuildSetMember(string fieldName, object value)
        {

            if (fieldName == "Status")
            {
                return new KeyValuePair<string, object>("Status", (int)((SupportStatus)value));
            }
            else
            {
                return base.BuildSetMember(fieldName, value);
            }
        }

        protected override string BuildCondition()
        {
            var ids = this.EntitySet.Select(i => i.Id).ToArray();

            if (ids.Length == 0)
            {
                return " 1=2 ";
            }
            else
            {
                return " Id in (" + string.Join(", ", ids) + ") ";
            }
        }
    }
}
